package com.atguigu.map;

import com.atguigu.set.FileOperation;
import org.junit.Test;

import java.util.ArrayList;

public class WordFrequency {

    public static void main(String[] args) {
        System.out.println("Pride and Prejudice");
        ArrayList<String>words=new ArrayList<>();
        String filename="pride-and-prejudice.txt";
        if(FileOperation.readFile(filename,words)){
            System.out.println("Total words："+words.size());
//            LinkedListMap<String,Integer>map=new LinkedListMap<>();
            BSTMap<String,Integer>map=new BSTMap<>();
            for(String word:words){
                /*if(map.contains(word)){
                    map.set(word,map.get(word)+1);
                }else{
                    map.add(word,1);
                }*/
                Integer count = map.get(word);
                map.add(word,count==null?1:count+1);
            }
            System.out.println("Total different words: "+map.getSize());
            System.out.println("Frequency of PRIDE: "+map.get("pride"));
            System.out.println("Frequency of PREJUDICE: "+map.get("prejudice"));
            System.out.println(map);
        }
    }

}
